package com.ruoyi.project.qyxy.orgdtl.controller;

import java.util.List;

import com.ruoyi.project.qyxy.orgdtl.domain.OrgScoreDetailInfo;
import com.ruoyi.project.qyxy.persondtl.domain.QuaPersonSocreDetail;
import com.ruoyi.project.qyxy.persondtl.service.IQuaPersonSocreDetailService;
import com.ruoyi.project.qyxy.quadtl.domain.QuaSocreDetail;
import com.ruoyi.project.qyxy.quadtl.service.IQuaSocreDetailService;
import com.ruoyi.project.tool.utils.DoubleUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.qyxy.orgdtl.domain.OrgScoreDetail;
import com.ruoyi.project.qyxy.orgdtl.service.IOrgScoreDetailService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 企业得分明细Controller
 * 
 * @author lcl
 * @date 2021-03-05
 */
@RestController
@RequestMapping("/qyxy/orgdtl")
public class OrgScoreDetailController extends BaseController
{
    @Autowired
    private IOrgScoreDetailService orgScoreDetailService;

    @Autowired
    private IQuaSocreDetailService quaSocreDetailService;

    @Autowired
    private IQuaPersonSocreDetailService quaPersonSocreDetailService;

    @GetMapping("/getOrgScoreDetail")
    public AjaxResult getOrgScoreDetail(String orgCode){
        OrgScoreDetailInfo detailInfo = new OrgScoreDetailInfo();
        //资质类别得分
        OrgScoreDetail typeScoreDetail = orgScoreDetailService.getByOrgCode(orgCode,"1");
        //资质人员得分
        OrgScoreDetail personScoreDetail = orgScoreDetailService.getByOrgCode(orgCode,"2");
        detailInfo.setTypeScore(typeScoreDetail.getScore().toString());
        detailInfo.setPersonScore(personScoreDetail.getScore().toString());
        detailInfo.setSumScore(DoubleUtils.add(typeScoreDetail.getScore(),personScoreDetail.getScore()).toString());
        //查询资质类别得分详细
        QuaSocreDetail quaSocreDetail = quaSocreDetailService.selectQuaSocreDetailById(typeScoreDetail.getDetailId());
        detailInfo.setTypeDetail(quaSocreDetail);
        //查询资质人员得分详细
        QuaPersonSocreDetail quaPersonSocreDetail = new QuaPersonSocreDetail();
        quaPersonSocreDetail.setDetailId(personScoreDetail.getId());
        List<QuaPersonSocreDetail> quaPersonSocreDetails = quaPersonSocreDetailService.selectQuaPersonSocreDetailList(quaPersonSocreDetail);
        detailInfo.setPersonDetailList(quaPersonSocreDetails);
        return AjaxResult.success(detailInfo);
    }

    /**
     * 查询企业得分明细列表
     */
    @PreAuthorize("@ss.hasPermi('qyxy:orgdtl:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrgScoreDetail orgScoreDetail)
    {
        startPage();
        List<OrgScoreDetail> list = orgScoreDetailService.selectOrgScoreDetailList(orgScoreDetail);
        return getDataTable(list);
    }

    /**
     * 导出企业得分明细列表
     */
    @PreAuthorize("@ss.hasPermi('qyxy:orgdtl:export')")
    @Log(title = "企业得分明细", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OrgScoreDetail orgScoreDetail)
    {
        List<OrgScoreDetail> list = orgScoreDetailService.selectOrgScoreDetailList(orgScoreDetail);
        ExcelUtil<OrgScoreDetail> util = new ExcelUtil<OrgScoreDetail>(OrgScoreDetail.class);
        return util.exportExcel(list, "orgdtl");
    }

    /**
     * 获取企业得分明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('qyxy:orgdtl:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(orgScoreDetailService.selectOrgScoreDetailById(id));
    }


    /**
     * 修改企业得分明细
     */
    @PreAuthorize("@ss.hasPermi('qyxy:orgdtl:edit')")
    @Log(title = "企业得分明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrgScoreDetail orgScoreDetail)
    {
        return toAjax(orgScoreDetailService.updateOrgScoreDetail(orgScoreDetail));
    }

    /**
     * 删除企业得分明细
     */
    @PreAuthorize("@ss.hasPermi('qyxy:orgdtl:remove')")
    @Log(title = "企业得分明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(orgScoreDetailService.deleteOrgScoreDetailByIds(ids));
    }
}
